package com.qualitair44.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qualitair44.R;
import com.qualitair44.constantes.ConstantesVilles;
import com.qualitair44.data.Mesure;
import com.qualitair44.data.utils.AirUtils;
import com.qualitair44.data.utils.Retriever;

public class MyStationActivity extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mystation_layout);
		
		new updateMesureCourante().execute(null);
		
	}

	public void fillIndice(Mesure m) {
		TextView tNivAir = (TextView)findViewById(R.id.niv_air);
		TextView tNivAzote = (TextView)findViewById(R.id.niv_azote);
		TextView tNivOzone = (TextView)findViewById(R.id.niv_ozone);
		TextView tNivSouffre = (TextView)findViewById(R.id.niv_souffre);
		TextView tNivPart = (TextView)findViewById(R.id.niv_part);
		
		LinearLayout linearLayout = (LinearLayout) findViewById(R.id.station);
		
		tNivAir.setText(String.valueOf(m.getIndice()));
		tNivAir.setTextColor(AirUtils.couleur(m.getIndice()));
		
		tNivAzote.setText(String.valueOf(m.getNO2()));
		tNivAzote.setTextColor(AirUtils.couleur(m.getNO2()));
		
		tNivSouffre.setText(String.valueOf(m.getS02()));
		tNivSouffre.setTextColor(AirUtils.couleur(m.getS02()));
		
		tNivOzone.setText(String.valueOf(m.getO3()));
		tNivOzone.setTextColor(AirUtils.couleur(m.getO3()));
		
		tNivPart.setText(String.valueOf(m.getPS()));
		tNivPart.setTextColor(AirUtils.couleur(m.getPS()));
		
		setContentView(linearLayout);
	}
	
	
	private class updateMesureCourante extends AsyncTask<Void, Void, Mesure> {

		@Override
		protected Mesure doInBackground(Void... params) {
			return Retriever.getNow(ConstantesVilles.NANTES);
		}

		protected void onPostExecute(Mesure m) {
			fillIndice(m);
		}

	}
}
